using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Win32;
using System.Diagnostics.Contracts;
using Konst3d.Efficiency;

namespace PEM
{
    /// <summary>
    /// Interaction logic for CreateSuiteDialog.xaml
    /// </summary>
    public partial class CreateSuiteDialog : PersistentModalDialog
    {
        #region Properties

        public string SuiteFileName
        {
            get
            {
                return uiSuiteFilePathTextBox.Text;
            }
        }

        public bool SuitePasswordProtectionEnabled
        {
            get
            {
                return uiSuitePasswordProtectionCheckBox.IsChecked ?? false;
            }
        }

        public bool SuiteEncodingEnabled
        {
            get
            {
                return uiSuiteCryptographycProtectionCheckBox.IsChecked ?? false;
            }
        }

        public string SuiteLogin
        {
            get
            {
                return uiSuiteLoginTextBox.Text;
            }
        }

        public string SuitePassword
        {
            get
            {
                return uiSuitePasswordBox.Password;
            }
        }

        public ICryptographicEngine SuiteCryptographicEngine
        {
            get
            {
                return uiSuiteCryptographycProtectionComboBox.SelectedItem as ICryptographicEngine;
            }
        }

        public int SuiteCryptographicEngineID
        {
            get
            {
                return uiSuiteCryptographycProtectionComboBox.SelectedIndex;
            }
        }

        #endregion // Properties

        #region Constructor

        public CreateSuiteDialog(ICryptographicEngine[] cryptographicEngines)
        {
            Contract.Requires(cryptographicEngines != null);

            InitializeComponent();

            _cryptographicEngines = cryptographicEngines;

            foreach (var engine in _cryptographicEngines)
            {
                uiSuiteCryptographycProtectionComboBox.Items.Add(engine);
            }

            if (uiSuiteCryptographycProtectionComboBox.Items.Count > 0)
            {
                uiSuiteCryptographycProtectionComboBox.SelectedIndex = 0;
            }
        }

        #endregion // Constructor

        private void OnBrowseButtonClick(object sender, RoutedEventArgs e)
        {
            if (_saveFileDialog.ShowDialog() ?? false)
            {
                uiSuiteFilePathTextBox.Text = _saveFileDialog.FileName;
            }
        }

        private void OnCancelButtonClick(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }

        private void OnCreateButtonClick(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }

        #region Fields

        private SaveFileDialog _saveFileDialog = new SaveFileDialog();
        private ICryptographicEngine[] _cryptographicEngines;

        #endregion // Fields
    }
}
